package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import liumengbaio.lolzhangyoubao.Activity.Adapter.MoreTreasureMyAdapter;
import liumengbaio.lolzhangyoubao.Activity.Fragment.FragmentMoreTreasureMy;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/9.
 */
public class MoreTreasureMyActivity extends FragmentActivity {
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private MoreTreasureMyAdapter mtma;
    private FragmentMoreTreasureMy fmtm, fmt;
    private List<Fragment> lists;
    private List<String> names;
    private ImageView back;
    private TextView name, address;
    private CircleImageView circleImageView;
    private SharedPreferences sp;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_trreasure_my);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mTabLayout = (TabLayout) findViewById(R.id.more_treasure_myTab);
        mViewPager = (ViewPager) findViewById(R.id.more_treasure_myViewPage);
        back = (ImageView) findViewById(R.id.more_treasure_back);
        name = (TextView) findViewById(R.id.more_treasure_myName);
        address = (TextView) findViewById(R.id.more_treasure_address);
        circleImageView = (CircleImageView) findViewById(R.id.more_treasure_myPic);
    }

    private void initData() {
        lists = new ArrayList<>();
        names = new ArrayList<>();
        fmt = new FragmentMoreTreasureMy();
        fmtm = new FragmentMoreTreasureMy();
        lists.add(fmt);
        lists.add(fmtm);
        names.add("参与记录");
        names.add("幸运记录");
        mtma = new MoreTreasureMyAdapter(getSupportFragmentManager(), names, lists);
        mViewPager.setAdapter(mtma);
        mTabLayout.setupWithViewPager(mViewPager);

        sp = getSharedPreferences("userInfo", MODE_PRIVATE);
        Picasso.with(MoreTreasureMyActivity.this).load(sp.getString("headIcon", "")).into(circleImageView);
        name.setText(sp.getString("name", ""));
    }

    private void initEvent() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MoreTreasureMyActivity.this, MoreTreasureAddressActivity.class);
                startActivity(intent);
            }
        });
    }
}
